import { myLocalStorage } from '@/utils/storage'
import { USER_TOKEN, USER_REFRESH_TOKEN } from '@/constants'

export default {
  namespaced: true,
  state: () => {
    return {
      token: myLocalStorage.get(USER_TOKEN) || '',
      refresh_token: myLocalStorage.get(USER_REFRESH_TOKEN) || '',
    }
  },
  mutations: {
    // @设置 token
    setToken(state, payload) {
      state.token = payload
      myLocalStorage.set(USER_TOKEN, payload)
    },
    // @设置 refresh_token
    setRefreshToken(state, payload) {
      state.refresh_token = payload
      myLocalStorage.set(USER_REFRESH_TOKEN, payload)
    },
    // @清除 token
    removeToken(state) {
      state.token = ''
      myLocalStorage.remove(USER_TOKEN)
      state.refresh_token = ''
      myLocalStorage.remove(USER_REFRESH_TOKEN)
    },
  },
}
